package com.tqyan.model.enums;

import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;

/**
 * @description GPT绘画尺寸
 * <p>
 *     生成图像的大小。必须是256x256、512x512或 之一1024x1024。
 * </p>
 *
 * @author 陈晨
 * @date 2023/4/11 17:51
 */
@Getter
@AllArgsConstructor
public enum GPTSizeEnum {

    SIZE_256("256x256", "256x256", 16),
    SIZE_512("512x512", "512x512", 19),
    SIZE_1024("1024x1024", "1024x1024", 21),
    ;

    private final String value;
    private final String desc;
    private final long price;

    public static GPTSizeEnum get(String value) {
        if (null == value) {
            return null;
        }
        return Arrays.stream(GPTSizeEnum.values())
                .filter(e -> e.value.equals(value)).findFirst().orElse(null);
    }

    public static GPTSizeEnum getByDesc(String desc) {
        if (StringUtils.isBlank(desc)) {
            return null;
        }
        return Arrays.stream(GPTSizeEnum.values())
                .filter(e -> e.desc.equals(desc)).findFirst().orElse(null);
    }

    public static String getValueByDesc(String desc) {
        GPTSizeEnum getEnum = Arrays.stream(GPTSizeEnum.values())
                .filter(e -> e.desc.equals(desc)).findFirst().orElse(null);
        if (null == getEnum) {
            return null;
        }
        return getEnum.getValue();
    }

    @Override
    public String toString() {
        return JSONObject.toJSONString(this);
    }

}
